#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <stdio.h>

#include "G4SteppingManager.hh"                                                                   
#include "G4Track.hh"                                                                             
#include "G4Step.hh"
#include "G4StepPoint.hh"
#include "G4TrackStatus.hh"                                                                       
#include "G4VPhysicalVolume.hh"                                                                   
#include "G4ParticleDefinition.hh"                                                                
#include "G4ParticleTypes.hh"
#include "G4Run.hh"                                                                        
#include "G4RunManager.hh"                                                                        
#include "G4ios.hh"
#include "G4Timer.hh"



#include "Log.hh"

using namespace std;

Log::Log()
{
	cout << "Writing log file ... " << endl;
	timer = new G4Timer;
}

Log::~Log()
{
	cout << "Log file finished." << endl;
	delete timer;
}

void Log::BeginOfRunAction(const G4Run* theRun)
{
//
//	logfile.open("/home/jxfeng/lustre/CEPCUser/RICH-single/Log/LogSession.dat", ios_base::in | ios_base::out);
//	if (logfile.is_open())
//	{
//		cout << "Log file opened!" << endl;
//		logfile >> logNum;
//		cout << "Log file created: Log.txt" << endl;
//		logfile.seekg(0,logfile.beg);
//		if (logNum >= 9999){ logfile << setw(4) << setfill('0') << 0 << "\n"; }
//		else {logfile << setw(4) << setfill('0') <<(logNum + 1) << "\n";}
//		logNum = logNum + 1;
//		cout << "Log Number: " << logNum << endl;
//
//		logfile << G4cerr << flush;
//	}
//	else {cout << "Log file does not exist!" << endl; exit(0);}

//	char buffer[50];
//	sprintf(buffer, "/home/jxfeng/lustre/CEPCUser/RICH-single/Log/Log_%d.out", logNum);
//	//printf("%s", buffer, n);
//	cout << buffer << endl;
//	loginfo.open(buffer, ios_base::out);
//	if (loginfo.is_open())
//	{
//		//G4Step * theStep;
//		cout << "IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII" << endl;
//		cout << " theRun = " << theRun << "\tOOOOOOOOOOooooooooooPPPPPPPPPPpppppppppp" << endl;
//		//cout << " theRunID = " << theRun -> GetRunID() << "\tOOOOOOOOOOooooooooooPPPPPPPPPPpppppppppp" << endl;
//		timer -> Start();
//	}
	
//	logfile.close();
//	loginfo.close();
}
